{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "c0c789b6-a1d0-4173-9dcb-19f33db577a5",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "账户余额 = 150.0\n"
     ]
    }
   ],
   "source": [
    "from dataclasses import dataclass\n",
    "@dataclass\n",
    "class Account:\n",
    "    __balance: float\n",
    "\n",
    "    def __init__(self,balance):\n",
    "        self._balance = balance\n",
    "        if type(balance) == type('a'):\n",
    "            raise ValueError('账户余额必须是数')\n",
    "        self.__balance = float(balance)\n",
    "\n",
    "    @property\n",
    "    def balance(self):\n",
    "        return self.__balance\n",
    "\n",
    "    @balance.setter\n",
    "    def balance(self, value):\n",
    "        self.__balance = float(value)\n",
    "\n",
    "account = Account(100)\n",
    "account.balance += 50\n",
    "print(f'账户余额 = {account.balance}')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a93993fd-665b-43c1-8e1e-1a9a0e914d01",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
